<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>iterator</title>
  <script>

    /**
     * [Symbol.iterator]()方法返回一个新的 Iterator 对象，它遍历字符串的代码点，返回每一个代码点的字符串值。
     */

    const string = 'today weather good!';

    const iterator = string[Symbol.iterator]();

    console.log(iterator.next().value); // t
    console.log(iterator.next().value); // o
    console.log(iterator.next().value); // d
    console.log(iterator.next().value); // a
    console.log(iterator.next().value); // y

    for (let v of iterator) {
      console.log(v);
    }

    /** 字符串有迭代器才能被for...of所遍历,也有done属性 */

  </script>
</head>

<body>

</body>

</html>